package com.len.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.len.controller.req.BaseReq;
import com.len.entity.DayDataEntity;
import com.len.service.DataService;
import com.len.util.ReType;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping(value = "/shop/data")
@Slf4j
public class DataController {

    @Resource
    private DataService dataService;

    @GetMapping(value = "showDayDataList")
    @RequiresPermissions("data:showDayDataList")
    public String showDayDataList() {
        return "/shop/data/dayDataList";
    }

    @GetMapping(value = "getDayDataList")
    @ResponseBody
    @RequiresPermissions("data:showDayDataList")
    public String getDayDataList(BaseReq req, String page, String limit) {

        Page<DayDataEntity> tPage = new Page<>(Integer.parseInt(page), Integer.parseInt(limit));
        tPage = dataService.getDayDataList(req,tPage);
        ReType reType = new ReType(tPage.getTotal(), tPage.getResult());

        return JSON.toJSONString(reType);
    }


}
